<!--
* description: 缺件审核
* author: xiaochengzuan
* createdDate: 2021-1-28
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"

    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import { orgApis } from "@/api/paSparePartsManagement"

export default {
  name: 'shortageRegistration',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {

    // this.$refs['multipleTable'].data = [{bigAreaCode:'1'}]
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path



    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editPopupsVisible : false,
      editRowData: {},
      // 网格查询API配置对象
      // apiConfig: {
      //   ServiceCode: 'queryBigArea',
      //   APIUrl: '/mp/e3sh/basics/ve/bigareaService/queryBigArea.do'
      // },
      dynamicApiConfigs: orgApis.shortageAuditQueryList,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          // text: this.$t('sys.button.query'), // 查询
          text: '查询',
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [

                   {
              compKey: 'compKey1',
              labelName: '审核状态：',
              codeField: 'lackPartsStatus',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: 'PAD005', statusText: '已作废' },
                { statusId: 'PAD001', statusText: '已保存' },
                { statusId: 'PAD003', statusText: '已审核' },
                { statusId: 'PAD002', statusText: '已提交' },
                { statusId: 'PAD004', statusText: '已驳回' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '缺件单号：',
              codeField: 'lackPartsCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: 'VIN：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },


                   {
              compKey: 'compKey4',
              labelName: '车牌号：',
              codeField: 'carLicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
                 {
              compKey: 'compKey5',
              labelName: '登记日期：',
              codeField: "startDate,endDate",
                component: () =>
                  import("@/components/org/datePicker/andtDatePicker"),
                type:'YYYY-MM-DD',
                format: 'yyyy-MM-dd',
              isMul: false,
              isMust: false
            },

               {
              compKey: 'compKey6',
              labelName: '紧急度：',
              codeField: 'urgency',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '紧急' },
                { statusId: '0', statusText: '一般' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },
                      {
              compKey: 'compKey7',
              labelName: '客户名称：',
              codeField: 'customerName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn1',
              label: '操作',
              minWidth: 180,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '审核',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                },
                //    {
                //   compKey: 'propKey1',
                //   labelName: '作废',
                //   component: () => import('@/components/org/linkButton'),
                //   clickEvent: (index) => this.edit(index)
                // }
              ]
            },
            {
              prop: 'lackPartsCode',
              label: '缺件单号',
              hidden: false,
            //   alwaysHidden: true
            },
            {
              prop: 'associationTypeCn',
              label: '关联类型'
            },
                 {
              prop: 'associationNo',
              label: '关联单号'
            },
                 {
              prop: 'carLicense',
              label: '车牌号'
            },
                  {
              prop: 'vin',
              label: 'VIN'
            },
                   {
              prop: 'carConfigCode',
              label: '车型编码'
            },
                   {
              prop: 'lackVariety',
              label: '缺件品种数'
            },
                   {
              prop: 'customerName',
              label: '客户名称'
            },
                   {
              prop: 'registerPerson',
              label: '登记人员'
            },
                   {
              prop: 'registerDate',
              label: '登记日期'
            },
                   {
              prop: 'remark',
              label: '备注'
            },
          ],

      // 表单查询数据
      formField: this.$utils.getFormField(this, {
        lackPartsStatus: '',
        lackPartsCode: '',
        vin: '',
        carLicense: '',
        startDate: '',
        endDate: '',
        urgency: '',
        customerName: '',
        begin: '',
        end: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  mounted() {
    // 列表查询
    // this.queryTable(1)
    this.$refs.multipleTable.list = [
      {'releaseId':'1'}
    ]
  },

  methods: {
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
      console.log(this.editRowData,'editRowData')
    },


        //导出
    // export() {
    //   var date = new Date;
    //   var year=date.getFullYear()
    //   var month=date.getMonth()+1
    //   var day=date.getDate();
    //       month =(month<10 ? "0"+month:month)
    //       day =(day<10 ? "0"+day:day)
    //   var mydate = year.toString()+month.toString()+day.toString()
    //   const returnObj = {
    //       // api配置
    //     apiConfig: {
    //       APIUrl:'/mp/e3sh/basics/ve/CarTypeService/exportCarType.do',
    //     },
    //       variables: this.formField
    //     }
    //     returnObj.variables.dataType='excel'
    //     const paramD = this.$getParams(returnObj)
    //     this.$requestAPI(paramD).then(res=>{
    //     this.$utils.downloadFile(res,`车系维护${mydate}.xlsx`)
    //   })
    // },
  }
}
</script>
